import cv2
import numpy as np

def draw_labels_on_image(image, labels):
    for label in labels:
        x, y, w, h = label
        cv2.rectangle(image, (int(x - w / 2), int(y - w / 2)), (int(x + w / 2), int(y + h / 2)), (0, 0, 255), 2)
    
    cv2.imshow('Demo', image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


if __name__ == "__main__":
    image = cv2.imread("examples/1.jpg")
    H, W, C = image.shape
    labels = np.loadtxt("examples/1.txt", dtype = np.float32)
    labels[:, 1::2] *= W
    labels[:, 2::2] *= H
    draw_labels_on_image(image, labels[1:])